<template>
    <el-row class="main-cont padd20">
        <el-row class="mb20">
            <el-col class="title box box-pack-between box-align-center">
                <el-page-header @back="$router.go(-1)" content="添加">
                </el-page-header>
            </el-col>

        </el-row>

        <el-row>
            <el-col class="title box box-pack-between">
                <el-form ref="form" :model="form" label-width="80px" :rules="rules">
                    <el-col class="box box-align-center">
                        <el-form-item label="学年学期">
                            <el-select v-model="form.xnxq" placeholder="请选择" @change="handleSelect" class="text">
                                <el-option :label="`${item.xn + '-' + item.xq}`" :value="item.xn + '-' + item.xq"
                                    v-for="(item, index) in xqList" :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="选择证书" prop="zs">
                            <el-select v-model="form.zsId" placeholder="请选择" @change="handleSelectcert" class="text">
                                <el-option :label="item.name" :value="item.id" v-for="(item, index) in zsList"
                                    :key="index"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col class="btn">
                        <el-form-item label="颁发对象">
                            <el-button class="reset-comfirm-btn" @click="openPopup">调取学生劳动课成绩</el-button>
                            <el-button class="reset-comfirm-btn" @click="openPopupsj()">调取学生劳动实践成绩</el-button>
                        </el-form-item>
                    </el-col>

                </el-form>
            </el-col>
        </el-row>

        <el-row class="mt20 btn">
            <el-col v-if="list.length != 0">
                <el-table :data="list" stripe style="width: 100%"
                    :header-cell-style="{ background: '#F0F1F8', color: '#2F3142' }" border>
                    <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
                    <el-table-column prop="xj" label="学级" width="80" :show-overflow-tooltip="true"
                        align="center"></el-table-column>
                    <el-table-column prop="zymc" label="专业" :show-overflow-tooltip="true" align="center"></el-table-column>
                    <el-table-column prop="bjmc" label="班级" :show-overflow-tooltip="true" align="center"></el-table-column>
                    <el-table-column prop="name" label="姓名" width="80" :show-overflow-tooltip="true"
                        align="center"></el-table-column>
                    <el-table-column prop="sn" label="学号" align="center" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="cousScore" label="课程分" width="120" align="center"></el-table-column>
                    <el-table-column prop="ldsjScore" label="实践分" width="120" align="center"></el-table-column>
                    <!--                    <el-table-column prop="attchScore" label="附加项得分" width="120" align="center"></el-table-column>
                    <el-table-column prop="zongheScore" label="综合得分" width="120" align="center"></el-table-column> -->
                </el-table>
                <el-col class="mt20">
                    <el-button class="reset-comfirm-btn" @click="clickAddZs">添加到颁发列表</el-button>
                </el-col>
            </el-col>
            <el-col v-else>
                <el-empty description="暂无记录" image="../../../static/image/nodata/nodata.png"></el-empty>
            </el-col>
        </el-row>

        <stuScore :dialogVisible="stuScore" @closeTk="closeTk" @backstulist="setData2" :xnxq="form.xnxq" :zsId="form.zsId"
            :zsName="form.zsName"></stuScore>
        <StuScoreSj ref="sj" :dialogVisible="stuScoreSj" @closeTk="closeTkSj" @backstulist="setData2" :xnxq="form.xnxq"
            :zsId="form.zsId" :zsName="form.zsName"></StuScoreSj>
    </el-row>
</template>

<script>
import stuScore from './components/stuScore.vue';
import StuScoreSj from './components/stuScoreSj.vue';

export default {
    components: {
        stuScore,
        StuScoreSj
    },
    data() {
        return {
            form: {
                xnxq: '',
                zsId: '',
                zsName: ''
            },
            stuScore: false,
            stuScoreSj: false,
            schoolid: this.$store.state.schoolId,
            list: [],
            xqList: [],
            zsList: [],
            lineForm: {},
            rules: {
                zs: [
                    { required: true, message: '请选择证书', trigger: 'blur' },
                ]
            }
        };
    },
    created() {
        this.getXqList();
        this.getCertData()
    },
    methods: {
        tableRowClassName({
            row,
            rowIndex
        }) {
            if (rowIndex === 1) {
                return 'warning-row';
            } else if (rowIndex === 3) {
                return 'success-row';
            }
            return '';
        },
        setData2(data, lineForm) {
            console.log(data, lineForm);
            this.list = data
            this.lineForm = lineForm
        },
        closeTk() {
            this.stuScore = false;
        },
        closeTkSj() {
            this.stuScoreSj = false;
        },
        openPopup() {
            if (this.zsList.length == 0) {
                this.$message.warning('请先选择证书');
                return
            }
            this.stuScore = true
        },
        openPopupsj() {
            // console.log(111);
            if (this.zsList.length == 0) {
                this.$message.warning('请先选择证书');
                return
            }
            this.stuScoreSj = true
            this.$refs.sj.setData()
        },
        //添加到颁发列表
        clickAddZs() {
            let params = {
                schoolId: this.schoolid,
                xn: this.form.xnxq.split('-')[0],
                xq: this.form.xnxq.split('-')[1].substr(0, 3),
                zydm: this.lineForm.zydm.split('-')[0],
                zymc: this.lineForm.zymc,
                xj: this.lineForm.xj,
                xjfw: this.lineForm.xj + '级',
                certId: this.form.zsId,
                name: this.form.zsName,
                unitType: Number(this.lineForm.unitType.split('-')[0]),
                unit: this.lineForm.unitTitle,
                numType: Number(this.lineForm.type),
                value: Number(this.lineForm.value),
                hasCous: this.lineForm.kcChecked == true ? 1 : 0,
                hasLdsj: this.lineForm.sjChecked == true ? 1 : 0,
                // hasAttch:this.lineForm.fjChecked == true?1:0,
                // cousPercent:this.lineForm.cousPercent,
                // ldsjPercent:this.lineForm.ldsjPercent,
                // attchPercent:this.lineForm.attchPercent
            };
            this.$api.Admin.certPubAdd(params).then(res => {
                console.log(res);
                if (res.code == '0') {
                    this.$message.success('添加成功');
                    this.$router.go(-1)
                } else {
                    this.$message.error('请求失败！');
                }
            })

        },
        //证书查询
        getCertData() {
            var params = {
                schoolid: this.schoolid
            };
            this.$api.Admin.getCertData(params).then(res => {
                console.log(res);
                if (res.code == '0') {
                    this.zsList = res.list;
                    this.form.zsId = res.list[0].id
                    this.form.zsName = res.list[0].name
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        getXqList() {
            let params = {
                schoolid: this.schoolid
            };
            this.$api.Admin.getXqList(params).then(res => {
                if (res.code == '0') {
                    this.xqList = res.list;
                    res.list.map(res => {
                        if (res.isCur == 1) {
                            this.form.xnxq = res.xn + '-' + res.xq
                            this.getBfList()
                        }
                    })
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        getBfList() {
            let params = {
                schoolid: this.schoolid,
                xn: this.form.xnxq.split('-')[0],
                xq: this.form.xnxq.split('-')[1]
            };
            this.$api.Admin.getBfList(params).then(res => {
                if (res.code == '0') {
                    this.bfList = res.list;
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        changeStatus(userid, status) {
            var params = {
                'userId': userid,
                'status': status
            };
            this.$api.szhgl.qyjy(params).then(res => {
                if (res.code == '0') {
                    this.$message.success('操作成功！');
                    this.glylb();
                } else {
                    this.$message.error('请求失败！');
                }
            })
        },
        handleSelect() {
            // this.getBfList()
        },
        handleSelectcert(e) {
            this.zsList.forEach((res) => {
                if (e == res.id) {
                    this.form.zsName = res.name;
                }
            })
        },
        clickAdd() {

        }
    }
}
</script>

<style scoped lang="scss">
.bf-btn {
    padding: 3px 5px;
    width: 64px;
    height: 24px;
    background: linear-gradient(-7deg, #FF9B4F, #FFBC3A);
    border-radius: 12px;
    color: #fff;
    cursor: pointer;
}

.el-table .warning-row {
    background: oldlace;
}

.el-table .success-row {
    background: #f0f9eb;
}
</style>
